<template>
  <div style="margin-top: 30px;margin-left:200px; width: 700px;">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="公司名称" prop="name">
        <el-input v-model="ruleForm.name" style="width: 300px"></el-input>
      </el-form-item>

      <el-form-item label="规模(人数)" prop="num">
        <el-input v-model="ruleForm.num" style="width: 100px"></el-input>
      </el-form-item>

      <el-form-item label="地址" prop="area">
        <el-input v-model="ruleForm.area" style="width: 600px"></el-input>
      </el-form-item>

     <el-form-item label="创建时间" required>
        <el-col :span="11">
          <el-form-item>
            <el-date-picker  placeholder="选择日期" v-model="ruleForm.estTime"  style="width: 100%;"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-form-item>

       <el-form-item label="公司类型" prop="industryType">
        <el-input v-model="ruleForm.industryType" style="width: 600px"></el-input>
      </el-form-item>

      <el-form-item label="注册资金" prop="regMoney">
        <el-input v-model="ruleForm.regMoney" style="width: 200px"></el-input>
      </el-form-item>

      <el-form-item label="是否上市" prop="license">
        <el-input v-model="ruleForm.license"></el-input>
      </el-form-item>
      <el-form-item label="CEO" prop="regName">
        <el-input v-model="ruleForm.regName"></el-input>
      </el-form-item>
      <el-form-item label="简介" prop="brief">
        <el-input type="textarea" v-model="ruleForm.brief"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即发布</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  data() {
    return {
      ruleForm: {
        name: "",
        num: "",
        area: "",
        estTime: "",
        industryType: "",
        regMoney: "",
        license:"",
        brief:"",
        regName:"",
     
      },
      rules: {
        name: [{ required: true, message: "请输入职位名称", trigger: 'blur' }],
        estTime: [{ required: true, message: "请选择创建日期", trigger: 'change'}],
        area: [{ required: true, message: "工作地点", trigger: 'blur' }],
        num: [{ required: true, message: "公司规模", trigger: "blur" } ],
        industryType:[{ required: true, message: "公司类型", trigger: "blur" } ],
        regMoney: [{ required: true, message: "注册资金", trigger: "blur" }],
        license: [{ required: true, message: "是否上市", trigger: "blur" }],
        regName: [{ required: true, message: "请输入CEO", trigger: "blur" }],
        brief: [{ required: true, message: "公司简介", trigger: "blur" }],
    }
    };
  },
  methods: {
    submitForm(formName) {
      const _this = this;
      this.$refs[formName].validate(valid => {
        //提交后
         if (valid) {
            /*  console.log(_this.ruleForm) */
            axios.post('http://localhost:8182/company/insert'+'/'+_this.companyuser.cuid,_this.ruleForm).then(function (resp) {
                            if(resp.data.code == 0){
                                _this.$alert(_this.ruleForm.name+'添加成功', '', {
                                    confirmButtonText: '确定',
                                    callback: action => {
                                        _this.$router.push('/companyList')
                                    }
                                });
                            }
                        }) 
                    }
                });
            },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  created(){
        const _this = this
         let companyuser = JSON.parse(window.localStorage.getItem('companyuser'))
       _this.companyuser = companyuser
     /*   console.log(_this.companyuser.cuid) */
  }
};
</script>